<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小六壬吉凶预测</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            font-family: 'Microsoft YaHei', sans-serif;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            min-height: 100vh;
            padding: 20px;
        }
        
        .container {
            max-width: 800px;
            margin: 0 auto;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 20px;
            padding: 30px;
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            backdrop-filter: blur(10px);
        }
        
        .header {
            text-align: center;
            margin-bottom: 30px;
        }
        
        .title {
            font-size: 2.5em;
            color: #333;
            margin-bottom: 10px;
            background: linear-gradient(45deg, #667eea, #764ba2);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .subtitle {
            color: #666;
            font-size: 1.1em;
        }
        
        .input-section {
            background: #f8f9fa;
            padding: 25px;
            border-radius: 15px;
            margin-bottom: 25px;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        label {
            display: block;
            margin-bottom: 8px;
            font-weight: bold;
            color: #333;
        }
        
        input, select {
            width: 100%;
            padding: 12px;
            border: 2px solid #ddd;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s;
        }
        
        input:focus, select:focus {
            outline: none;
            border-color: #667eea;
        }
        
        .btn-group {
            display: flex;
            gap: 15px;
            justify-content: center;
            margin-top: 20px;
        }
        
        .btn {
            padding: 12px 30px;
            border: none;
            border-radius: 25px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: all 0.3s;
        }
        
        .btn-primary {
            background: linear-gradient(45deg, #667eea, #764ba2);
            color: white;
        }
        
        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(102, 126, 234, 0.4);
        }
        
        .btn-secondary {
            background: #f8f9fa;
            color: #333;
            border: 2px solid #ddd;
        }
        
        .btn-secondary:hover {
            background: #e9ecef;
        }
        
        .result-section {
            margin-top: 30px;
            padding: 25px;
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            border-radius: 15px;
            display: none;
        }
        
        .result-card {
            background: white;
            padding: 20px;
            border-radius: 10px;
            margin-bottom: 15px;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        .result-title {
            font-size: 1.3em;
            font-weight: bold;
            margin-bottom: 10px;
            color: #333;
        }
        
        .gua-name {
            font-size: 2em;
            font-weight: bold;
            text-align: center;
            margin: 15px 0;
            padding: 15px;
            background: linear-gradient(45deg, #ff6b6b, #ee5a24);
            color: white;
            border-radius: 10px;
        }
        
        .interpretation {
            line-height: 1.6;
            color: #555;
            margin: 10px 0;
        }
        
        .lucky-color {
            display: inline-block;
            width: 30px;
            height: 30px;
            border-radius: 50%;
            margin: 0 5px;
            vertical-align: middle;
        }
        
        .calculation-process {
            background: #f8f9fa;
            padding: 15px;
            border-radius: 8px;
            margin-top: 15px;
            font-family: monospace;
            font-size: 0.9em;
            color: #666;
        }
        
        @media (max-width: 600px) {
            .container {
                padding: 20px;
            }
            
            .title {
                font-size: 2em;
            }
            
            .btn-group {
                flex-direction: column;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="header">
            <h1 class="title">小六壬预测</h1>
            <p class="subtitle">传统易学占卜，预测吉凶祸福</p>
        </div>
        
        <div class="input-section">
            <div class="form-group">
                <label for="question">请输入您要预测的事情：</label>
                <input type="text" id="question" placeholder="例如：今天出行是否顺利？">
            </div>
            
            <div class="form-group">
                <label for="datetime">选择预测时间：</label>
                <input type="datetime-local" id="datetime">
            </div>
            
            <div class="form-group">
                <label for="method">计算方法：</label>
                <select id="method">
                    <option value="time">按时间推算</option>
                    <option value="random">随机起卦</option>
                </select>
            </div>
            
            <div class="btn-group">
                <button class="btn btn-primary" onclick="predict()">开始预测</button>
                <button class="btn btn-secondary" onclick="clearAll()">重新开始</button>
            </div>
        </div>
        
        <div class="result-section" id="resultSection">
            <div class="result-card">
                <div class="result-title">预测结果</div>
                <div class="gua-name" id="guaName"></div>
                <div class="interpretation" id="interpretation"></div>
            </div>
            
            <div class="result-card">
                <div class="result-title">详细分析</div>
                <div id="detailAnalysis"></div>
            </div>
            
            <div class="result-card">
                <div class="result-title">建议与提醒</div>
                <div id="advice"></div>
            </div>
            
            <div class="calculation-process" id="calculationProcess"></div>
        </div>
    </div>

    <script>
        // 小六壬的六个基本卦象
        const liurenGua = {
            1: {
                name: "大安",
                type: "吉",
                meaning: "大安为事业有成，诸事平安之象",
                interpretation: "此卦大吉，诸事顺遂。求财得财，求官得官，婚姻美满，出行平安。但宜静不宜动，稳扎稳打方能长久。",
                advice: "保持现状，稳步前进。适宜签约、合作、投资等重要决定。",
                color: "#4CAF50"
            },
            2: {
                name: "留連",
                type: "凶",
                meaning: "留連为羁绊阻滞，事多延迟之象",
                interpretation: "此卦主阻滞延迟，做事不顺，容易遇到阻碍。求财难得，感情纠缠，出行不利。需要耐心等待时机。",
                advice: "暂缓行动，等待时机。不宜做重要决定，宜静观其变。",
                color: "#FF9800"
            },
            3: {
                name: "速喜",
                type: "吉",
                meaning: "速喜为快速成功，喜事临门之象",
                interpretation: "此卦主快速成功，喜事连连。求财速得，感情顺利，考试有成。但来得快去得也快，需要珍惜。",
                advice: "把握机会，快速行动。适宜求职、表白、考试等急需结果的事情。",
                color: "#E91E63"
            },
            4: {
                name: "赤口",
                type: "凶", 
                meaning: "赤口为口舌是非，争执不和之象",
                interpretation: "此卦主口舌是非，容易与人发生争执。投资有损，感情不和，健康需注意。需要谨言慎行。",
                advice: "谨言慎行，避免争执。不宜投资、诉讼，宜多行善事积德。",
                color: "#F44336"
            },
            5: {
                name: "小吉",
                type: "吉",
                meaning: "小吉为小有收获，渐入佳境之象",
                interpretation: "此卦主小有收获，事情会慢慢好转。求财小得，感情稳定，学业进步。虽不大富大贵，但安稳平顺。",
                advice: "循序渐进，积小成大。适宜学习、储蓄、养生等长期规划。",
                color: "#8BC34A"
            },
            6: {
                name: "空亡",
                type: "凶",
                meaning: "空亡为空虚落空，白费心机之象",
                interpretation: "此卦主竹篮打水一场空，努力付出却难有回报。求财落空，感情无果，计划难成。需要调整方向。",
                advice: "重新审视目标，调整策略。不宜投资、创业，宜反思总结。",
                color: "#9E9E9E"
            }
        };

        // 设置默认时间为当前时间
        document.getElementById('datetime').value = new Date().toISOString().slice(0, 16);

        function predict() {
            const question = document.getElementById('question').value;
            const datetime = new Date(document.getElementById('datetime').value);
            const method = document.getElementById('method').value;
            
            if (!question.trim()) {
                alert('请输入您要预测的事情');
                return;
            }
            
            let guaIndex;
            let calculationText;
            
            if (method === 'time') {
                // 按时间推算
                const month = datetime.getMonth() + 1;
                const day = datetime.getDate();
                const hour = datetime.getHours();
                
                // 小六壬计算公式：月+日+时，除以6取余数
                const sum = month + day + Math.floor((hour + 1) / 2);
                guaIndex = (sum % 6) || 6;
                
                calculationText = `计算过程：月(${month}) + 日(${day}) + 时辰(${Math.floor((hour + 1) / 2)}) = ${sum}，${sum} ÷ 6 = ${Math.floor(sum/6)}...${guaIndex}`;
            } else {
                // 随机起卦
                guaIndex = Math.floor(Math.random() * 6) + 1;
                calculationText = `随机起卦，得到卦象编号：${guaIndex}`;
            }
            
            const gua = liurenGua[guaIndex];
            
            // 显示结果
            document.getElementById('guaName').textContent = gua.name;
            document.getElementById('guaName').style.background = gua.type === '吉' ? 
                'linear-gradient(45deg, #4CAF50, #8BC34A)' : 
                'linear-gradient(45deg, #F44336, #FF5722)';
            
            document.getElementById('interpretation').innerHTML = `
                <strong>卦象含义：</strong>${gua.meaning}<br><br>
                <strong>详细解释：</strong>${gua.interpretation}
            `;
            
            document.getElementById('detailAnalysis').innerHTML = `
                <p><strong>吉凶属性：</strong><span style="color: ${gua.color}; font-weight: bold;">${gua.type === '吉' ? '吉卦 ✓' : '凶卦 ⚠'}</span></p>
                <p><strong>幸运色彩：</strong><span class="lucky-color" style="background-color: ${gua.color};"></span></p>
                <p><strong>预测问题：</strong>${question}</p>
                <p><strong>预测时间：</strong>${datetime.toLocaleString('zh-CN')}</p>
            `;
            
            document.getElementById('advice').innerHTML = `
                <div style="padding: 15px; background: ${gua.type === '吉' ? '#e8f5e8' : '#ffeaea'}; border-radius: 8px; border-left: 4px solid ${gua.color};">
                    ${gua.advice}
                </div>
            `;
            
            document.getElementById('calculationProcess').textContent = calculationText;
            document.getElementById('resultSection').style.display = 'block';
            
            // 滚动到结果区域
            document.getElementById('resultSection').scrollIntoView({ 
                behavior: 'smooth', html
                block: 'start' 
            });
        }
        
        function clearAll() {
            document.getElementById('question').value = '';
            document.getElementById('datetime').value = new Date().toISOString().slice(0, 16);
            document.getElementById('method').value = 'time';
            document.getElementById('resultSection').style.display = 'none';
        }
        
        // 添加回车键预测功能
        document.getElementById('question').addEventListener('keypress', function(e) {
            if (e.key === 'Enter') {
                predict();
            }
        });
    </script>
</body>
</html>